﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Driver;
using System.Configuration;

namespace MongoServices
{
	/// <summary>
	/// The default MongoServices default MongoUrl provider.
	/// </summary>
	public static class MongoServicesMongoUrlProvider
	{
		#region Static Methods
		/// <summary>
		/// Provides the default MongoUrl for the MongoServices.
		/// </summary>
		/// <returns>The appropriate MongoUrl.</returns>
		public static MongoUrl GetMongoUrl()
		{
			var connectionStringName = "MongoServiceConnectionString";

			if (ConfigurationManager.ConnectionStrings[connectionStringName] == null)
				throw new ApplicationException("The '" + connectionStringName + "' was not specified in the configuration file.");

			return new MongoUrlBuilder(ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString).ToMongoUrl();
		}
		#endregion
	}
}
